import StarModel from '../../model/starModel/starModel.js';
import { GetConnection, GetResult } from "../../util/db.js";
import { JoinSQLInsertKeys } from "../../util/JoinSQL.js";

class StarService {
    /**
     * @param {{starring:string,beStarred:string}} condition 
     */
    static async InsertStar(condition) {
        try {
            const model = new StarModel(condition)
            const conn = await GetConnection()
            let { keys, values } = model.GetKeys_Values()
            let sql = "insert into star"
            sql += JoinSQLInsertKeys(keys)
            const { rows: result } = await GetResult(sql, [[values]], conn, true)
            return result && result.affectedRows;
        } catch (error) {
            return Promise.reject(error)
        }
    }
}

export default StarService;